﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="assets/css/layui.css">
    <link rel="stylesheet" href="assets/css/login.css">
    <link rel="icon" href="/favicon.ico">
    <title>快递e栈管理后台</title>
</head>
<body class="login-wrap">
    <div class="login-container">
    	<h3>快递e栈后台管理</h3>
        <form class="login-form" action="index.html">
            <div class="input-group">
                <input type="text" id="username" class="input-field">
                <label for="username" class="input-label">
                    <span class="label-title">用户名</span>
                </label>
            </div>
            <div class="input-group">
                <input type="password" id="password" class="input-field">
                <label for="password" class="input-label">
                    <span class="label-title">密码</span>
                </label>
            </div>
            <button type="button" class="login-button">登录<i class="ai ai-enter"></i></button>
        </form>
    </div>
</body>
<script src="assets/layui.js"></script>
<script src="js/index.js" data-main="login"></script>
<script src="js/login.js" data-main="login"></script>
<script src="js/qrcode/jquery2.1.4.js"></script>
<script src="js/layer-v3.5.1/layer/layer.js"></script>
<script>
    function check($, $span) {
        if (($span.text() === '用户名') ? ($.val().trim() === '') : ($.val() === '')) {
            $span.css('color', 'red');
            return false;
        } else {
            $span.css('color', '');
            return true;
        }
    }

    $(function () {
        const $username = $('#username');
        const $password = $('#password');
        let $label1 = $("label[for='username'] > span");
        let $label2 = $("label[for='password'] > span");
        $username.bind('input propertychange', function () {
            check($username, $label1)
        });
        $password.bind('input propertychange', function () {
            check($password, $label2)
        });

        if ($username.val().trim() !== '') {
            let $parent = $username.parent();
            if (!$parent.hasClass('field-focus')) {
                $parent.addClass('field-focus');
            }
        }

        $('.login-button').click(function () {
            if (check($username, $label1) && check($password, $label2)) {
                let load = layer.load();
                $.post('login.do', {name:$username.val(),password:$password.val()}, function (data) {
                    layer.close(load);
                    layer.msg(data.message);
                    if (data.status === 0) {
                        location.href = 'index.html';
                    }
                }, 'JSON');
            }

        })
    })
</script>
</html>